<?php
// 测试登录接口
$url = 'http://127.0.0.2/island/api/index.php?r=user/login';

// 测试数据
$data = [
    'username' => '15876555525',
    'password' => '111111'
];

// 初始化cURL
$ch = curl_init($url);

// 设置cURL选项
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json'
]);

// 执行请求
$response = curl_exec($ch);

// 检查错误
if(curl_errno($ch)) {
    echo 'Error: ' . curl_error($ch);
} else {
    // 美化输出响应
    $decoded = json_decode($response, true);
    echo json_encode($decoded, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
}

// 关闭cURL
curl_close($ch);
?>